package blog.utils;

import java.util.List;

/**
 * @author qipan
 * @date 2019/11/28 9:20
 */
public class PageBean<T> {
    /**
     * 当前页
     * 此数据来源: 页面传递
     */
    private Long pageNum;
    /**
     * 每页条数
     * 此数据来源: 页面传递
     */
    private Long pageSize = (long)5;
    /**
     * 每页的分页数据
     * 此数据来源: 数据库查询
     */
    private List<T> pageData;
    /**
     * 总页数
     * 此数据来源: 根据totalCounts和pageSize计算得出
     */
    private Long totalPages;
    /**
     * 总记录数
     * 此数据来源: 数据库查询
     */
    private Long totalCounts;

    public Long getPageNum() {
        return pageNum;
    }

    public void setPageNum(Long pageNum) {
        if (pageNum == 0) {
            return;
        }
        this.pageNum = pageNum;
    }

    public Long getPageSize() {
        return pageSize;
    }

    public void setPageSize(Long pageSize) {
        this.pageSize = pageSize;
    }

    public List<T> getPageData() {
        return pageData;
    }

    public void setPageData(List<T> pageData) {
        this.pageData = pageData;
    }

    public Long getTotalPages() {
        long result = getTotalCounts() % getPageSize();
        if (result == 0) {
            totalPages = getTotalCounts() / getPageSize();
        } else {
            totalPages = getTotalCounts() / getPageSize() + 1;
        }
        return totalPages;
    }

    public void setTotalPages(Long totalPages) {
        this.totalPages = totalPages;
    }

    public Long getTotalCounts() {
        return totalCounts;
    }

    public void setTotalCounts(Long totalCounts) {
        this.totalCounts = totalCounts;
    }

    @Override
    public String toString() {
        return "PageBean{" +
                "pageNum=" + pageNum +
                ", pageSize=" + pageSize +
                ", pageData=" + pageData +
                ", totalPages=" + totalPages +
                ", totalCounts=" + totalCounts +
                '}';
    }
}
